package com.hiv.client.model.weixin;

import com.hiv.client.model.base.Amount;
import com.hiv.client.model.base.Payer;
import com.hiv.config.WechatConfigurationConfig;
import com.hiv.utils.MoneyUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WeixinJsCreateOrderReq implements Serializable {
  /** 应用ID：是 */
  private String appid;
  /** 直连商户号：是  */
  private String mchid;
  /** 商品描述：是 */
  private String description;
  /** 商户订单号：是 */
  private String out_trade_no;
  /** 附加数据：是 */
  private String attach;
  /** 通知地址：是 */
  private String notify_url;
  /** 订单金额：是 */
  private Amount amount;
  /** 支付人 */
  private Payer payer;

  /**
   * 创建预支付单
   * @param payMoney
   * @param openId
   */
  public WeixinJsCreateOrderReq(String mainOrderNum, Double payMoney, String attach, String openId) {
    this.appid = WechatConfigurationConfig.wxUserWechatAppid;
    this.mchid = WechatConfigurationConfig.wxUserWechatMerchantId;
    this.notify_url = WechatConfigurationConfig.wxUserWechatPayNotifyUrl;
    this.description = "宅狸家维修服务";
    this.out_trade_no = mainOrderNum;
    this.attach = attach;
    this.amount = new Amount(MoneyUtil.yuan2fen(payMoney), "CNY");
    this.payer = new Payer(openId);
  }
}
